<html>
<head><meta charset="utf-8"><title>Is this a bug? · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Is.20this.20a.20bug.3F.html">Is this a bug?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="184616066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Is%20this%20a%20bug%3F/near/184616066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Is.20this.20a.20bug.3F.html#184616066">(Jan 01 2020 at 22:24)</a>:</h4>
<p>I'm seeing an error that doesn't make any sense to me. I'm curious if I should file this as a bug in the compiler or if there's a legitimate problem with my code. Link to playground: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=315c87d507b242669f2b6243dc802b53" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=315c87d507b242669f2b6243dc802b53">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=315c87d507b242669f2b6243dc802b53</a> (edit: simplified code in playground)</p>



<a name="184616089"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Is%20this%20a%20bug%3F/near/184616089" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Is.20this.20a.20bug.3F.html#184616089">(Jan 01 2020 at 22:25)</a>:</h4>
<p>I could understand if the problem was on line 31, where I'm getting a reference that locks self to immutable, and then I can't pass self as a mutable reference. But the error pointing to line 27 makes no sense, especially since line 28 immediately returns that value!</p>



<a name="184616143"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Is%20this%20a%20bug%3F/near/184616143" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Is.20this.20a.20bug.3F.html#184616143">(Jan 01 2020 at 22:26)</a>:</h4>
<p>My thought to fix the (or what  I thought was the original) error was to add a call to <code>clone</code> (see modified example here: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=beaa001ec10a1d7b5eeec6bc77103180" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=beaa001ec10a1d7b5eeec6bc77103180">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=beaa001ec10a1d7b5eeec6bc77103180</a>) on line 31, but I still run into the same issue.</p>



<a name="184618615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Is%20this%20a%20bug%3F/near/184618615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Is.20this.20a.20bug.3F.html#184618615">(Jan 01 2020 at 23:45)</a>:</h4>
<p>Here's another variation further simplified without any async: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=425f9be6798d37b7291582629ac184cb" target="_blank" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=425f9be6798d37b7291582629ac184cb">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=425f9be6798d37b7291582629ac184cb</a></p>



<a name="184618733"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Is%20this%20a%20bug%3F/near/184618733" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Is.20this.20a.20bug.3F.html#184618733">(Jan 01 2020 at 23:48)</a>:</h4>
<p>I was able to solve it with this version: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=ecdc7880c62b9071abd4971a07c0b012" target="_blank" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=ecdc7880c62b9071abd4971a07c0b012">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=ecdc7880c62b9071abd4971a07c0b012</a> I find it pretty unexpected to be honest though. Is this an edge case fixed by polonius?</p>



<a name="184622905"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Is%20this%20a%20bug%3F/near/184622905" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Is.20this.20a.20bug.3F.html#184622905">(Jan 02 2020 at 02:09)</a>:</h4>
<p>Yes. Pretty sure this is another form of <a href="https://stackoverflow.com/q/38023871/155423" target="_blank" title="https://stackoverflow.com/q/38023871/155423">Returning a reference from a HashMap or Vec causes a borrow to last beyond the scope it's in?</a>.</p>



<a name="184622914"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Is%20this%20a%20bug%3F/near/184622914" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Is.20this.20a.20bug.3F.html#184622914">(Jan 02 2020 at 02:09)</a>:</h4>
<p>And yes, Polonius should address it; this is NLL case <a href="https://github.com/rust-lang/rust/issues/3" target="_blank" title="https://github.com/rust-lang/rust/issues/3">#3</a>.</p>



<a name="184626578"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Is%20this%20a%20bug%3F/near/184626578" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Is.20this.20a.20bug.3F.html#184626578">(Jan 02 2020 at 04:05)</a>:</h4>
<p>Ok, that's helpful to know. Thank you!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>